package com.tian.system.common.security;

import com.tian.framework.security.config.OwnKeycloakToken;
import com.tian.common.core.domain.AjaxResult;
import com.tian.system.domain.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityCommon {

    /**
     * 获取当前登录用户信息
     *
     * @return
     */
    public User getUser() {
        AjaxResult ajaxResult = new AjaxResult();
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        OwnKeycloakToken ownKeycloakToken = (OwnKeycloakToken) authentication;
        User user = (User) ownKeycloakToken.getSecurityUser();
        return user;
    }
}
